package com.su02.multi.util;

import org.apache.commons.collections4.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class List2MapUtil {
    private List2MapUtil() {}

    public static <E> Map<Integer, E> convertList2Map(List<E> elems) {
        if (CollectionUtils.isEmpty(elems)) {
            return Map.of();
        }
        int sz = CollectionUtils.size(elems);
        Map<Integer, E> m = new HashMap<>(sz);
        for (int i = 0; i < sz; i++) {
            m.put(i, elems.get(i));
        }
        return m;
    }
}
